﻿using System;
using System.IO;
using System.IO.Compression;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 一个负责压缩解压数据字节的类
	/// </summary>
	// Token: 0x020001A2 RID: 418
	public class SoftZipped
	{
		/// <summary>
		/// 压缩字节数据
		/// </summary>
		/// <param name="bytes">等待被压缩的数据</param>
		/// <exception cref="T:System.ArgumentNullException"></exception>
		/// <returns>压缩之后的字节数据</returns>
		// Token: 0x0600212A RID: 8490 RVA: 0x000A13D8 File Offset: 0x0009F5D8
		public static byte[] CompressBytes(byte[] bytes)
		{
			bool flag = bytes == null;
			if (flag)
			{
				throw new ArgumentNullException("bytes");
			}
			byte[] result;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
				{
					gzipStream.Write(bytes, 0, bytes.Length);
				}
				result = memoryStream.ToArray();
			}
			return result;
		}

		/// <summary>
		/// 解压压缩后的数据
		/// </summary>
		/// <param name="bytes">压缩后的数据</param>
		/// <exception cref="T:System.ArgumentNullException"></exception>
		/// <returns>压缩前的原始字节数据</returns>
		// Token: 0x0600212B RID: 8491 RVA: 0x000A1454 File Offset: 0x0009F654
		public static byte[] Decompress(byte[] bytes)
		{
			bool flag = bytes == null;
			if (flag)
			{
				throw new ArgumentNullException("bytes");
			}
			byte[] result;
			using (MemoryStream memoryStream = new MemoryStream(bytes))
			{
				using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
				{
					using (MemoryStream memoryStream2 = new MemoryStream())
					{
						int num = 1024;
						byte[] buffer = new byte[num];
						int count;
						while ((count = gzipStream.Read(buffer, 0, num)) > 0)
						{
							memoryStream2.Write(buffer, 0, count);
						}
						result = memoryStream2.ToArray();
					}
				}
			}
			return result;
		}
	}
}
